From f0d03727f69a84daff484ea9a7944d9c29daa5c3 Mon Sep 17 00:00:00 2001
From: trisusilo48 <tri.susilo@altama.co.id>
Date: Thu, 24 Oct 2024 15:02:04 +0700
Subject: done page category brand

---
 src/pages/shop/find/[slug].jsx | 51 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 src/pages/shop/find/[slug].jsx

(limited to 'src/pages/shop/find/[slug].jsx')

diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx
new file mode 100644
index 00000000..4666add5
--- /dev/null
+++ b/src/pages/shop/find/[slug].jsx
@@ -0,0 +1,51 @@
+import axios from 'axios';
+import { useRouter } from 'next/router';
+import { useEffect, useState } from 'react';
+import Seo from '@/core/components/Seo';
+import dynamic from 'next/dynamic';
+
+const BasicLayout = dynamic(() =>
+  import('@/core/components/layouts/BasicLayout')
+);
+const ProductSearch = dynamic(() =>
+  import('@/lib/product/components/ProductSearch')
+);
+
+const BASE_URL = 'https://indoteknik.com';
+export default function FindPage() {
+  const route = useRouter();
+  const url = BASE_URL + route.asPath;
+  const [result, setResult] = useState(null);
+  const [query, setQuery] = useState(null);
+
+  const getUrls = async (url) => {
+    try {
+      let response = await axios(
+        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?url=${url}`
+      );
+      let result = response?.data?.response?.docs[0] || null;
+      setResult(result);
+    } catch (error) {
+      console.error('Error fetching data:', error);
+    }
+  };
+
+  useEffect(() => {
+    getUrls(url);
+  }, []);
+
+  useEffect(() => {
+    if (result) {
+      let fq = `category_parent_ids:${result.category_id_i} AND manufacture_id_i:${result.brand_id_i}`;
+      setQuery({
+        fq : fq
+      });
+    }
+  }, [result]);
+
+  return (
+    <BasicLayout>
+      {query && <ProductSearch query={query} prefixUrl={`${route.asPath}`} />}
+    </BasicLayout>
+  );
+}
-- 
cgit v1.2.3

